<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>积分明细</title>
	<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
	<script type="text/javascript" src="js/userJScript.js"></script>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css" />
	<link rel="stylesheet" href="./css/userStyle.css"/>
	<link rel="stylesheet" href="https://at.alicdn.com/t/font_2150071_oqmbug6i2f.css"/>
  </head>
  <style>
	 body{
		 width:100%;
		 min-width: 300px;
		 height:100%
	 }
	 .searchBar{
		 width:99%;
		 margin-top: 5px;
		/* border: 2px solid #000000; */
	 }
	 .demoTable{
		/* border: 1px solid #0000FF; */
		 height:90%;
		 width: 99%;
		 margin-top:0px;
		 margin: 0 auto;
	 }
	 .container{
	   width: 350px;
	   height: 350px;
	   margin: 10px;
	   padding: 20px;
	   border-radius: 8px;
	   box-shadow: 0 3px 18px rgba(28, 19, 19, 0.5);
	   font-size: 16px;
	 }
	.layui-form-item{
		 margin: 0px;
		 padding: 0px;
	 }
	 .layui-table-tool{
		 padding: 2px;
	 }
	 #toolbarDemo{
		 position: relative;
		 bottom: 10px;
	 }
  </style>
  <body>
	  <!-- 搜索开始-->
	  <div class="searchBar">
		<form class="layui-form" action="">
			<div class="layui-form-item" style=" margin: 0px;padding: 0px;">
				  <div class="layui-inline" >
 				<label class="layui-form-label"  style="width: 50px;">操作：</label>
				<div class="layui-input-inline" style="width: 8.3rem;">
			    <select name="type" lay-filter="typeSelect">
			      <option value="1" >收入</option>
			      <option value="2">支出</option>
			    </select>
			  </div>
			</div>
		        <div class="layui-inline">
				   <div class="layui-input-inline">
				      <button type="submit" class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
				      <button type="reset" class="layui-btn ">重置</button>
				   </div>
				</div>  
			</div>
		</form>
	  </div>
	  <!--搜索结束 -->
	  <!-- 数据表格开始-->
	 <div class="demoTable">
		  <table class="layui-hide" id="user" lay-filter="user"></table> 
	</div>
	
	<!--数据表格结束  -->
   </body>
<!-- script开始 -->
  <div class="layui-btn ">
	  <a href="./integral.html">返回</a>
  </div>
	<!-- 头部工具栏结束 -->
	<!-- layui开始 -->
	<script src="layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript">
	layui.use(['table','layer','form','laydate'], function(){
			var table = layui.table;
			var layer = layui.layer;
			var form = layui.form;
			var laydate=layui.laydate;
			var search;		
	laydate.render({
			  elem: '#entryTime'
			  ,range: true
			});
	laydate.render({
			  elem: '#outTime'
			  ,min:2
			  ,max:7
			});

  //方法级渲染
  var tableIns=table.render({
    elem: '#user'
   ,url:'/garbage/getByType'
   ,method:'POST'
   ,contentType: 'application/json'
   ,where:{'type':1}
/*   ,toolbar:"#toolbarDemo" */
	,height:'full-110'
	,cellMinWith:100
   ,defaultToolbar: ['']
    ,cols: [[
		{type: 'checkbox', fixed: 'left',width: 110}
      ,{field:'id', title: 'ID', fixed: true}
      ,{field:'type', title: '操作',
	  templet:function(d){
	  		  switch(d.type){
				  case 1:
					  return "收入";
				  case 2:
					  return "支出";
	  		  }
	  }}
		  ,{field:'createTime', title: '时间'}
		  , {field:'weight', title: '余额'}

    ]]
	,page: true
	  , parseData: function(res) { //res 即为原始返回的数据
		  return {
			  "code": res.code, //解析接口状态
			  "msg": res.msg, //解析提示文本
			  "count": res.data.total, //解析数据长度
			  "data": res.data.records //解析数据列表
		  };
	  }
	  , response: {
		  statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
	  }
	  ,request: {
    	pageName: "displayStart",
		  limitName: "displayLength"
	  }
  });
/*搜索表单提交 */
  form.on('submit(search)', function(data){
		table.reload('user',{
			where: data.field,
			page:{
				curr :1,
			},
		})
	  return false;
    });

  form.on('select(typeSelect)', function(data){
	  table.reload('user',{
		  where: {'type':data.value},
		  page:{
			  curr :1,
		  },
	  })
	  return false;
  });
  /* 监听复选框*/
  table.on('checkbox(user)',function(obj){
	  fillApplyTab();
  });
/*出库申请表单提交 */
  form.on('submit(apply)', function(data){
	  $.ajax({
	    url:'transport/add',
	    method:'POST',
	    contentType: 'application/json',
	    data:JSON.stringify(data.field),
	    success: function(res) {
				layer.alert(res.msg, {
					end: function(){
							if (res.code == 200) console.log("success");
				         }
				    })
					console(1);
					layer.closeAll('iframe'); 
				}   
		})
    });
/*填写表单*/
	function fillApplyTab(){
	  var checkStatus = table.checkStatus('user');
	  if(checkStatus.data.length==0){
	   layer.msg('请先选择要申请的数据！', {icon: 2});
	   return;
	  }
	  var codeId = [];
	  for(var i=0;i<checkStatus.data.length;i++){
			codeId.push(checkStatus.data[i].id);
	  }
	  $("input[name='garbageIds']").val(codeId);
	  $("input[name='type']").val(checkStatus.data[0].type);
	};
});


</script>
</html>